package com.znsb.msfq.utils;

import android.net.ParseException;
import android.text.TextUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * yg 时间
 */
//默认为24小时制HH 12hh
public class GetIsparityTime {
    private static String time;
    private static int index;

    /**
     * 获取当前时间
     *
     * @param time
     * @return
     */
    public static String NowTimeNMD() {
        SimpleDateFormat formatters = new SimpleDateFormat("yyyy-MM-dd");
        Date curDates = new Date(System.currentTimeMillis());// 获取当前时间
        time = formatters.format(curDates);
        return time;
    }

    public static String NowTimeAll() {
        SimpleDateFormat formatters = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date curDates = new Date(System.currentTimeMillis());// 获取当前时间
        time = formatters.format(curDates);
        return time;
    }

    public static String NowTimeNM() {
        SimpleDateFormat formatters = new SimpleDateFormat("yyyy-MM");
        Date curDates = new Date(System.currentTimeMillis());// 获取当前时间
        time = formatters.format(curDates);
        return time;
    }

    public static String NowTimeMD() {
        SimpleDateFormat formatters = new SimpleDateFormat("MM-dd");
        Date curDates = new Date(System.currentTimeMillis());// 获取当前时间
        time = formatters.format(curDates);
        return time;
    }

    public static String NowTimeD() {
        SimpleDateFormat formatters = new SimpleDateFormat("dd");
        Date curDates = new Date(System.currentTimeMillis());// 获取当前时间
        time = formatters.format(curDates);
        return time;
    }

    public static String NowTimeH() {
        SimpleDateFormat formatters = new SimpleDateFormat("HH");
        Date curDates = new Date(System.currentTimeMillis());// 获取当前时间
        time = formatters.format(curDates);
        return time;
    }

    // 输入时间返回早中晚
    // yyyy-MM-dd hh:mm:ss-->上午
    public static String NowTimeday(String time) {
        if (time.length() == 18) {
            // 2015-9-23 09:28:30
            index = Integer.parseInt(time.substring(10, 12));
        } else if (time.length() == 19) {
            // 1970-01-01 01:00:00
            index = Integer.parseInt(time.substring(11, 13));
        }
        if (index < 8 || index > 18) {// 晚上
            time = "晚上";
        } else if (index > 8 && index < 12) {// 上午
            time = "上午";
        } else {// 下午
            time = "下午";
        }
        return time;
    }

    /**
     * 输入时间返回时间戳  2015年09月30日08时22分15秒-->1443571710
     *
     * @param time
     * @return
     */
    public static String InputTimeAll(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        Date date;
        String times = null;
        try {
            date = sdr.parse(time);
            long l = date.getTime();
            String stf = String.valueOf(l);
            times = stf.substring(0, 10);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return times;
    }

    /**
     * 输入时间戳返回时间 1443571710-->2015-9-30 0:0:0  10位
     *
     * @param time
     * @return
     */
    public static String InputTimetampAll(String time) {
        if (TextUtils.isEmpty(time) || "null".equals(time))
            return "";
        if (time.length() > 9) {
            time = time.substring(0, 10);
        }
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int i = Integer.parseInt(time);
        String times = sdr.format(new Date(i * 1000L));
        return times;
    }

    public static String InputTimetamp(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd");
        long lcc = Long.valueOf(time);
        int i = Integer.parseInt(time);
        String times = sdr.format(new Date(i * 1000L));
        return times;
    }

    public static String InputTime(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd");
        long lcc = Long.valueOf(time);
        int i = Integer.parseInt(time);
        String times = sdr.format(new Date(i * 1000L));
        return times;
    }

    public static String InputTimetamphour(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("HH");
        long lcc = Long.valueOf(time);
        int i = Integer.parseInt(time);
        String times = sdr.format(new Date(i * 1000L));
        return times;
    }

    public static String InputTimetampminute(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("mm");
        long lcc = Long.valueOf(time);
        int i = Integer.parseInt(time);
        String times = sdr.format(new Date(i * 1000L));
        return times;
    }

    public static String InputTimetampNumber(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyyMMdd");
        long lcc = Long.valueOf(time);
        int i = Integer.parseInt(time);
        String times = sdr.format(new Date(i * 1000L));
        return times;
    }

    /**
     * 输入时间戳变星期 1443571710-->星期二
     *
     * @param time
     * @return
     */
    public static String TimestampWeek(long timeStamp) {
        int mydate = 0;
        String week = null;
        Calendar cd = Calendar.getInstance();
        cd.setTime(new Date(timeStamp * 1000L));
        mydate = cd.get(Calendar.DAY_OF_WEEK);
        // 获取指定日期转换成星期几
        if (mydate == 1) {
            week = "周日";
        } else if (mydate == 2) {
            week = "周一";
        } else if (mydate == 3) {
            week = "周二";
        } else if (mydate == 4) {
            week = "周三";
        } else if (mydate == 5) {
            week = "周四";
        } else if (mydate == 6) {
            week = "周五";
        } else if (mydate == 7) {
            week = "周六";
        }
        return week;
    }

    /**
     * 输入日期如（2014-06-14）返回（星期数）
     *
     * @param time
     * @return
     */
    public static String Timeweek(String time) {
        Date date = null;
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd");
        int mydate = 0;
        String week = null;
        try {
            try {
                date = sdr.parse(time);
            } catch (java.text.ParseException e) {
                e.printStackTrace();
            }
            Calendar cd = Calendar.getInstance();
            cd.setTime(date);
            mydate = cd.get(Calendar.DAY_OF_WEEK);
            // 获取指定日期转换成星期几
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (mydate == 1) {
            week = "星期日";
        } else if (mydate == 2) {
            week = "星期一";
        } else if (mydate == 3) {
            week = "星期二";
        } else if (mydate == 4) {
            week = "星期三";
        } else if (mydate == 5) {
            week = "星期四";
        } else if (mydate == 6) {
            week = "星期五";
        } else if (mydate == 7) {
            week = "星期六";
        }
        return week;
    }

    /**
     * 当前时间变星期
     *
     * @param time
     * @return
     */
    public static String NowTimeweek() {
        SimpleDateFormat formatters = new SimpleDateFormat("yyyy-MM-dd");
        Date curDates = new Date(System.currentTimeMillis());// 获取当前时间
        String now = formatters.format(curDates);
        Date date = null;
        int mydate = 0;
        String week = null;
        try {
            try {
                date = formatters.parse(now);
            } catch (java.text.ParseException e) {
                e.printStackTrace();
            }
            Calendar cd = Calendar.getInstance();
            cd.setTime(date);
            mydate = cd.get(Calendar.DAY_OF_WEEK);
            // 获取指定日期转换成星期几
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (mydate == 1) {
            week = "星期日";
        } else if (mydate == 2) {
            week = "星期一";
        } else if (mydate == 3) {
            week = "星期二";
        } else if (mydate == 4) {
            week = "星期三";
        } else if (mydate == 5) {
            week = "星期四";
        } else if (mydate == 6) {
            week = "星期五";
        } else if (mydate == 7) {
            week = "星期六";
        }
        return week;

    }
}
